﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ProjectSchedule.Entity
{
    public class XZProcessPlanArry_Section
    {
        public XZProcessPlanArry_Section() { }
        public XZProcessPlanArry_Section(IEnumerable<XZSectionProgress_Section> models)
        {
            this.Data = models.ToList();
        }
        public IList<XZSectionProgress_Section> Data { get; set; }

        public Int32 CompleteCount
        {
            get
            {
                return Data.Where(m => m.IsComplete).Count();
            }
        }
        public double CompleteWeight
        {
            get
            {
                if (CompleteCount > 0)
                {
                    return Data.Where(m => m.IsComplete).Select(m => m.Weight).Aggregate((m, n) => m + n);
                }
                return 0;
            }
        }
        public Int32 BeginCount
        {
            get
            {
                return Data.Where(m => m.IsBegin).Count();
            }
        }
        public double BeginWeight
        {
            get
            {
                if (BeginCount > 0)
                {
                    return Data.Where(m => m.IsBegin).Select(m => m.Weight).Aggregate((m, n) => m + n);
                }
                return 0;
            }
        }
        public double ProgressWeight
        {
            get
            {
                return Data.Select(m => m.Weight * (m.EndPrecent - m.BeginPrecent) / 100).Aggregate((m, n) => m + n);
            }
        }
        public double AuditWeight
        {
            get
            {
                return ProgressWeight;
            }
        }
    }
    public class XZProcessPlanDict_Section
    {
        public XZProcessPlanDict_Section(IEnumerable<XZSectionProgress_Section> models)
        {
            Dicts = new Dictionary<string, XZProcessPlanArry_Section>();
            var keys = models.Select(m => m.UnitName).Distinct();
            foreach (var key in keys)
            {
                Dicts[key] = new XZProcessPlanArry_Section(models.Where(m => m.UnitName.Equals(key)));
            }
        }
        public IDictionary<string, XZProcessPlanArry_Section> Dicts;
        public Int32 Length
        {
            get
            {
                return Dicts == null ? 0 : Dicts.Count;
            }
        }
    }

    public class XZProcessPlanArry_Area
    {
        public XZProcessPlanArry_Area() { }
        public XZProcessPlanArry_Area(IEnumerable<XZSectionProgress_Area> models)
        {
            this.Data = models.ToList();
        }
        public IList<XZSectionProgress_Area> Data { get; set; }

        public Int32 CompleteCount
        {
            get
            {
                return Data.Where(m => m.IsComplete).Count();
            }
        }
        public double CompleteWeight
        {
            get
            {
                if (CompleteCount > 0)
                {
                    return Data.Where(m => m.IsComplete).Select(m => m.Weight).Aggregate((m, n) => m + n);
                }
                return 0;
            }
        }

        public Int32 BeginCount
        {
            get
            {
                return Data.Where(m => m.IsBegin).Count();
            }
        }
        public double BeginWeight
        {
            get
            {
                if (BeginCount > 0)
                {
                    return Data.Where(m => m.IsBegin).Select(m => m.Weight).Aggregate((m, n) => m + n);
                }
                return 0;
            }
        }

        public double ProgressWeight
        {
            get
            {
                return Data.Select(m => m.Weight * (m.EndPrecent - m.BeginPrecent) / 100).Aggregate((m, n) => m + n);
            }
        }

        public double AuditWeight
        {
            get
            {
                return ProgressWeight;
            }
        }
    }
    public class XZProcessPlanDict_Area
    {
        public XZProcessPlanDict_Area(IEnumerable<XZSectionProgress_Area> models)
        {
            Dicts = new Dictionary<string, XZProcessPlanArry_Area>();
            var keys = models.Select(m => m.UnitName).Distinct();
            foreach (var key in keys)
            {
                Dicts[key] = new XZProcessPlanArry_Area(models.Where(m => m.UnitName.Equals(key)));
            }
        }
        public IDictionary<string, XZProcessPlanArry_Area> Dicts;
        public Int32 Length
        {
            get
            {
                return Dicts == null ? 0 : Dicts.Count;
            }
        }
    }

    public class XZProcessPlanArry_Debug
    {
        public XZProcessPlanArry_Debug() { }
        public XZProcessPlanArry_Debug(IEnumerable<XZSectionProgress_Debug> models)
        {
            this.Data = models.ToList();
        }
        public IList<XZSectionProgress_Debug> Data { get; set; }

        public Int32 CompleteCount
        {
            get
            {
                return Data.Where(m => m.IsComplete).Count();
            }
        }
        public double CompleteWeight
        {
            get
            {
                return 0;
            }
        }
        public Int32 BeginCount
        {
            get
            {
                return Data.Where(m => m.IsBegin).Count();
            }
        }
        public double BeginWeight
        {
            get
            {
                return 0;
            }
        }
        public double ProgressWeight
        {
            get
            {
                return 0;
            }
        }
        public double AuditWeight
        {
            get
            {
                return ProgressWeight;
            }
        }
    }
    public class XZProcessPlanDict_Debug
    {
        public XZProcessPlanDict_Debug(IEnumerable<XZSectionProgress_Debug> models)
        {
            Dicts = new Dictionary<string, XZProcessPlanArry_Debug>();
            var keys = models.Select(m => m.UnitName).Distinct();
            foreach (var key in keys)
            {
                Dicts[key] = new XZProcessPlanArry_Debug(models.Where(m => m.UnitName.Equals(key)));
            }
        }
        public IDictionary<string, XZProcessPlanArry_Debug> Dicts;
        public Int32 Length
        {
            get
            {
                return Dicts == null ? 0 : Dicts.Count;
            }
        }
    }
}
